package com.admin.action.bookaction;

import com.admin.Action;
import com.admin.service.bookservice.BookServiceImpl;
import com.admin.service.bookservice.BookServiceInF;
import com.pojo.BooksBean;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;


public class BookAddAction extends Action {
    @Override
    public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out=response.getWriter();
        //天啊及
        HttpSession session = request.getSession();
//        System.out.println(session.getAttribute("adminInfo"));
        if(session.getAttribute("adminInfo")==null){
            out.println("<script>parent.window.location.href='error.html';</script>");
            return;
        }


        String bookName=request.getParameter("bookName");
            String bookPrice=request.getParameter("bookPrice");
            String bookBorrowPrice=request.getParameter("bookBorrowPrice");
            String bookAuthor=request.getParameter("bookAuthor");
            String bookPress=request.getParameter("bookPress");
            String bookPubDate=request.getParameter("bookPubDate");
            String bookOriginalStock=request.getParameter("bookOriginalStock");
            Long bookTYpe= Long.valueOf(request.getParameter("bookTYpe"));
            String bookaddress=request.getParameter("bookaddress");
            String booknum=request.getParameter("booknum");

        BooksBean booksBean=new BooksBean();
        booksBean.setAddress(bookaddress);
        booksBean.setBookName(bookName);
        booksBean.setAuthor(bookAuthor);
        booksBean.setBorrowPrice(Double.parseDouble(bookBorrowPrice));
        booksBean.setPrice(Double.parseDouble(bookPrice));
        booksBean.setPress(bookPress);
        booksBean.setOriginalStock(Long.parseLong(bookOriginalStock));
        booksBean.setStock(50L);
        booksBean.setBookNumber(booknum);
        booksBean.setIsLower("0");

        System.out.println(bookPubDate);
        booksBean.setType(bookTYpe);
        booksBean.setPublicDate(bookPubDate);
        BookServiceInF bookServiceInF=new BookServiceImpl();
        Boolean b=bookServiceInF.insertBook(booksBean);
//
//        System.out.println(b);
        out.print(b);
    }
}
